/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package cn.eclass.bean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.eclass.bean.api.IAdCategoryBean;
import cn.eclass.dao.AdCategoryDao;
import cn.eclass.entity.AdCategoryEntity;

/**
 *
 * @author Administrator
 */
public class AdCategoryBean implements IAdCategoryBean {

    private AdCategoryDao dao = new AdCategoryDao();
	private static HashMap<String, Integer> map = null;

    @Override
    public List<AdCategoryEntity> list() {
    	return dao.getList();
    }

    @Override
    public Map<String, Integer> getMap() {
    	List<AdCategoryEntity> list = list();
    	if(map!=null) return map;
    	map = new HashMap<String, Integer>();
    	for(AdCategoryEntity adCat : list) {
    		map.put(adCat.getName(), adCat.getId());
    	}
    	return map;
    }
    
    @Override
    public boolean delete(int adCatId) {
        return dao.delete(adCatId);
    }

    @Override
    public boolean update(AdCategoryEntity adCategoryEntity) {
        return dao.update(adCategoryEntity);
    }

    @Override
    public AdCategoryEntity get(int theId) {
        return dao.select(theId);
    }

    @Override
    public AdCategoryEntity add(AdCategoryEntity entity) {
        return dao.add(entity);
    }
}
